//
//  DetailsListView.m
//  Comma
//
//  Created by dlios on 15-1-13.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DetailsListView.h"
#import "CustomTableViewCell.h"
#import "OnlyImageTableViewCell.h"
#import "OnlyTextTableViewCell.h"
#import "TextAndImageTableViewCell.h"
#import "HiddenView.h"
#import "GlobalMacro.h"
#import "DetailsListModel.h"
#import "HiddenView.h"
#import "AFNetWorkingYU.h"
#import "URLMacro.h"
#define OPENCENTERX 248.0
#define DIVIDWIDTH 70.0 //OPENCENTERX 对应确认是否打开或关闭的分界线。
@implementation DetailsListView

- (void)creatView
{
    [self.rightButton setTag:1];
    
    // 创建tableView
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT- 113) style:UITableViewStylePlain];
    
    // 五种重用池
    [_tableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:@"customCell"];
    [_tableView registerClass:[OnlyImageTableViewCell class] forCellReuseIdentifier:@"imageCell"];
    [_tableView registerClass:[OnlyTextTableViewCell class] forCellReuseIdentifier:@"textCell"];
    [_tableView registerClass:[TextAndImageTableViewCell class] forCellReuseIdentifier:@"textAndImageCell"];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        [_tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    
//    [_tableView setLayoutMargins:UIEdgeInsetsZero];
    [self addSubview:_tableView];
    
    // 创建隐藏view
    self.hiddenView = [[HiddenView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 0)];
    [_hiddenView setClipsToBounds:YES];
    [_hiddenView setBackgroundColor:BLACKCOLOR];
    [self addSubview:_hiddenView];
    
    // 画线
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 49.5, SCREEN_WIDTH, 0.5)];
    [line setBackgroundColor:LINEERGRAY];
    [self addSubview:line];
    
    // headerView上添加分类button
    self.categoryButton = [[UIButton alloc] initWithFrame:CGRectMake(53, 28, 27, 27)];
    [_categoryButton.layer setCornerRadius:13.5f];
    [self.headerView addSubview:_categoryButton];
    
    // headerView上添加信息button
    self.mailButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 89, 28, 27, 27)];
    [_mailButton setBackgroundImage:[UIImage imageNamed:@"Button_Latter"] forState:UIControlStateNormal];
    [self.headerView addSubview:_mailButton];
    
    self.mailLight = [[UIView alloc] initWithFrame:CGRectMake(23, 0, 8, 8)];

    self.mailLight.layer.cornerRadius = 4;
    self.mailLight.layer.masksToBounds = YES;
    [self.mailButton addSubview:self.mailLight];
    
    
    self.changeMail = [[UIView alloc] initWithFrame:CGRectMake(23, 0, 8, 8)];
   
    self.changeMail.layer.cornerRadius = 5;
    self.changeMail.layer.masksToBounds = YES;
    [self.mailButton addSubview:self.changeMail];
    
}
//开启定时器（不是计时器）
- (void)addTimer
{
    [self.mailLight setBackgroundColor:REDCOLOR];
    [self.changeMail setBackgroundColor:REDCOLOR];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.3 target:self selector:@selector(MyDynamicAnimation) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
//关闭定时器、、在controller里直接关闭就可以了
- (void)removeTimer
{
    [self.mailLight setBackgroundColor:[UIColor clearColor]];
    [self.changeMail setBackgroundColor:[UIColor clearColor]];
    [self.timer invalidate];
}

//动画效果(小红点闪烁)
- (void)MyDynamicAnimation
{
    
    [UIView animateWithDuration:1.2 animations:^{
        [self.changeMail setAlpha:0];
        self.changeMail.layer.cornerRadius = 12;
        
        [self.changeMail setFrame:CGRectMake(15, -8, 24, 24)];
        
        
    } completion:^(BOOL finished) {
        [self.changeMail setFrame:CGRectMake(23, 0, 8, 8)];
        self.changeMail.layer.cornerRadius = 4;
        [self.changeMail setAlpha:1];
    }];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
